<#if !groupCode??>
<div class="row">
	<div class="col-md-12">
		<div class="alert alert-danger" role="alert">
			<strong>无法创建字典项！</strong>
			无效的字典分组信息！
		</div>
	</div>
</div>
<#else>
<form class="form-add-dic" action="${request.contextPath}/config/dictionary/add" method="post">
	<input type="hidden" name="groupCode" value="${groupCode}">
	<input type="hidden" name="system" value="false">
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							值
						</div>
					</div>
					<input type="text" class="form-control not-empty" name="val" placeholder="最多30个汉字">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span>
							序号
						</div>
					</div>
					<input type="text" class="form-control not-empty number" name="sort" placeholder="只能是整数">
				</div>
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="$.suredy.closeModal();">关闭</div>
		</div>
	</div>
</form>

<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script src="${request.contextPath}/app/js/form-checker.js"></script>
<script type="text/javascript">
	$(function() {
		$('.btn.btn-submit').on('click', function(event) {
			var form = $('form.form-add-dic');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '添加失败！');
						$this.removeClass('disabled');
						return false;
					}

					$.suredy.loadContent('${request.contextPath}/config/dictionary/list/${groupCode}');

					$.suredy.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('添加失败！\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
